/*
 * Author Kyle Richardson
 */
package tests;

import static org.junit.Assert.*;

import java.util.HashMap;

import model.Job;
import model.Jobs;
import model.LMA;
import model.Volunteer;

import org.junit.Before;
import org.junit.Test;

/**
 * Tests to make sure that the non-getter/setter 
 * methods are running properly for Jobs class.
 * @author Kyle Richardson
 * @author Justin Kudlo
 */
public class JobsTest {
	
	Jobs myJobs;
	Job myJob1;
	Job myJob2;
	Job myJob3;
	Volunteer Tim;
	LMA Frank;
	
	/**
	 * Sets up variables for the tests.
	 */
	@Before
	public void setUp()
	{
		Frank = new LMA("Frank", "Romano", "5", "", "",
				"", "", "", null);
		myJobs = new Jobs();
		myJob1 = new Job("Cave Cleanout", 3, 4, Frank,
				40, 1, "");
		myJob2 = new Job("RiverSide Pickup", 3, 4, Frank,
				40, 1, "");
		myJob3 = new Job("Deer Passing Cleanup", 3, 4,
				Frank, 40, 1, "Watch out for Deer");
		Tim = new Volunteer("bob","pass",
				"1111111", null, null, null, null);
	}
	
	/**
	 * This test tries to add a job to the available job
	 * collection and then checks to see if the collection
	 * contains the job after adding it.
	 */
	@Test
	public void testaddNewJob()
	{
		myJobs.addNewJob(myJob1);
		HashMap<String, Job>theJobs = myJobs.getAllJobs();
		assertEquals(theJobs.containsKey(myJob1.getName()),
				true);	
	}
	
	/**
	 * Test add new request.
	 * 
	 * @author Justin Kudlo
	 */
	@Test
	public void testaddNewRequest()
	{
		myJobs.addNewRequest(myJob1);
		HashMap<String, Job> theRequestedJobs = myJobs.
		getRequestedJobs();
		assertEquals(theRequestedJobs.containsKey(myJob1.
				getName()), true);
	}
	
	/**
	 * This test adds a job to the available job
	 * collection and then tries to retrieve the same
	 * job from the collection and checks if it is the same
	 * one.
	 */
	@Test
	public void testfindJob()
	{
		myJobs.addNewJob(myJob1);
		Job theFoundJob = myJobs.findJob(myJob1.getName());
		assertEquals(theFoundJob, myJob1);
	}
	
	/**
	 * This test adds a job to the requested jobs 
	 * collection then attempts to get the job by removing
	 * it from the collection and saving it as a new job.
	 * Then checking if the new job is the same one that
	 * was requested.
	 */
	@Test
	public void testgetRequestedJob()
	{
		myJobs.addNewRequest(myJob1);
		Job recievedJob = myJobs.
		getRequestedJob(myJob1.getName());
		HashMap<String, Job> theRequestedJobs = myJobs.
		getRequestedJobs();
		assertEquals(theRequestedJobs.
				containsKey(recievedJob), false);
		assertEquals(recievedJob, myJob1);
	}
	
	/**
	 * This test adds three jobs to the available job
	 * collection and then signs up a volunteer for one
	 * of them. It then checks each job to make sure the
	 * volunteer only is signed up for the selected job.
	 */
	@Test
	public void testgetVolunteerJobs()
	{
		myJobs.addNewJob(myJob1);
		myJobs.addNewJob(myJob2);
		myJobs.addNewJob(myJob3);
		myJob1.signupForJobAsVol(Tim);
		HashMap<String, Job> volTimsJobs =
			myJobs.getVolunteersJobs(Tim);
		assertEquals(volTimsJobs.containsKey(
				myJob1.getName()), true);
		assertEquals(volTimsJobs.
				containsKey(myJob2.getName()), false);
		assertEquals(volTimsJobs.
				containsKey(myJob3.getName()), false);
	}
}
